<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>权限树扩展分享</title>
    <link rel="stylesheet" type="text/css" href="../js/layui/css/layui.css">
    <script type="text/javascript" src="../js/layui/layui.js"></script>
    <link rel="stylesheet" href="../css/tree.css">
</head>

<body>
    <div class="layui-container">
        <form class="layui-form">
            <div class="layui-form-item">
                <label class="layui-form-label">选择权限</label>
                <div class="layui-input-block">
                    <div id="LAY-auth-tree-index" class=" my-tree"></div>
                </div>
            </div>

        </form>
    </div>
</body>
<script>
    layui.config({
        base: '../js/extends/',
    }).extend({
        authtree: 'authtree',
    });
    layui.use(['jquery', 'authtree', 'form', 'layer'], function() {
        var $ = layui.jquery;
        var authtree = layui.authtree;
        var form = layui.form;
        var layer = layui.layer;
        // 一般来说，权限数据是异步传递过来的
        $.ajax({
            url: '../tree.json',
            dataType: 'json',
            success: function(data) {
                var trees = data.data.trees;
                // 如果后台返回的不是树结构，请使用 authtree.listConvert 转换
                authtree.render('#LAY-auth-tree-index', trees, {
                    inputname: 'authids[]',
                    layfilter: 'lay-check-auth',
                    autowidth: true,
                });
            }
        });
    });
</script>

</html>